package com.xzr.yespaper.service;

import com.xzr.yespaper.bean.Paper;
import com.xzr.yespaper.mapper.PaperMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PaperService {

    @Autowired
    PaperMapper paperMapper;

    /**
     * 得到作者 paper（未发表） --Get papers (unpublished) by author
     * @param name String (author's name)
     * @return List<Paper>
     */
    public List<Paper> getPaperByAuthor(String name){
        return paperMapper.getByAuthor(name);
    }

    /**
     * 得到作者 paper（已发表）--Get papers (published) by author
     * @param name String (author's name)
     * @return List<Paper>
     */
    public List<Paper> getPaperByAuthor2(String name){
        return paperMapper.getByAuthor2(name);
    }

    /**
     * 得到 reviewer 审阅的paper --Get papers by reviewer
     * @param name String (reviewer's name)
     * @return List<Paper>
     */
    public List<Paper> getPaperByReviewer(String name){
        return paperMapper.getByReviewer(name);
    }

    /**
     * 根据id得到paper --Get paper by paper id
     * @param paper com.xzr.yespaper.bean.Paper
     * @return Paper
     */
    public Paper getPaperByID(Paper paper){
        return paperMapper.getByID(paper);
    }

    /**
     * 得到所有paper --Get all papers
     * @return List<Paper>
     */
    public List<Paper> getAll(){
        return paperMapper.getAll();
    }

    /**
     * 得到所有 published paper --Get all papers(published)
     * @return List<Paper>
     */
    public List<Paper> getAllPub(){
        return paperMapper.getAllPub();
    }

    /***
     * 创建 paper --Create paper
     * @param paper com.xzr.yespaper.bean.Paper
     * @return boolean true or false 成功或失败(succeed or not)
     */
    public Boolean createPaper(Paper paper){
        try{
            paperMapper.createPaper(paper);
        }catch (Exception e){
            System.out.println(e);
            return false;
        }
        return true;
    }

    /***
     * 更新 paper --Update paper
     * @param paper com.xzr.yespaper.bean.Paper
     * @return boolean true or false 成功或失败(succeed or not)
     */
    public Boolean updatePaperInfo(Paper paper){
        try{
            paperMapper.updatePaperInfo(paper);
        }catch (Exception e){
            System.out.println(e);
            return false;
        }
        return true;
    }

    /***
     * 更新 paper地址 --Update paper address
     * @param paper com.xzr.yespaper.bean.Paper
     * @return boolean true or false 成功或失败(succeed or not)
     */
    public Boolean updatePaperAddress(Paper paper){
        try{
            paperMapper.updatePaperSource(paper);
        }catch (Exception e){
            System.out.println(e);
            return false;
        }
        return true;
    }

    /***
     * 更新 paper审核状态 --Update paper state
     * @param paper com.xzr.yespaper.bean.Paper
     * @return boolean true or false 成功或失败(succeed or not)
     */
    public Boolean updatePaperState(Paper paper){
        try{
            paperMapper.updatePaperState(paper);
        }catch (Exception e){
            System.out.println(e);
            return false;
        }
        return true;
    }

    /***
     * 删除 paper --Delete paper
     * @param paper com.xzr.yespaper.bean.Paper
     * @return boolean true or false 成功或失败(succeed or not)
     */
    public Boolean deletePaper(Paper paper){
        try{
            paperMapper.deletePaper(paper);
        }catch (Exception e){
            System.out.println(e);
            return false;
        }
        return true;
    }
}
